package com.ridanlabs.professorwebsite;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import com.ridanlabs.professorwebsite.models.UserProfile;

public class Util {
	
	/**
	 * @return UserProfile if there is an authenticated user, otherwise null.
	 */
	public static UserProfile getAuthenticatedUser() {
		Authentication a = SecurityContextHolder.getContext().getAuthentication();
		
		if( a == null ) //no body is authenticated
			return null;
		
		return (UserProfile)a.getPrincipal();
	}
	
}
